﻿using qcloudsms_csharp;

namespace Plugin.MessageProvider
{
    public class SMSService
    {
        /// <summary>
        /// 发送短信[寻程数据]
        /// </summary>
        /// <param name="va1">发送手机号</param>
        /// <param name="va2">发送内容</param>
        /// <param name="va3">发送签名</param>
        public SMSService(SMSParameter parameter)
        {
            this.phone = parameter.toPhone;
            this.context = parameter.context;
            this.sign = parameter.sign;
            this.templateId = parameter.templateId;
        }
        public class MethodResult<T>
        {
            public bool IsFinished { get; set; }

            /// <summary>
            /// 结果信息
            /// </summary>
            public string Discription { get; set; }

            /// <summary>
            /// 结果数据
            /// </summary>
            public T Date { get; set; }
        }
        /// <summary>
        /// 接收人手机号
        /// </summary>
        private string phone { get; set; }

        /// <summary>
        /// 发送内容
        /// </summary>
		private string context { get; set; }

        /// <summary>
        /// 签名
        /// </summary>
		private string sign { get; set; }

        /// <summary>
        /// 短信模板 ID，需要在短信控制台中申请
        /// </summary>
        private int templateId { get; set; }


        /// <summary>
        /// 短信应用 SDK AppID
        /// </summary>
        //int appid = 1400280565;
        int appid = 1400496034;

        /// <summary>
        /// 短信应用 SDK AppKey
        /// </summary>
        //string appkey = "188a422a6a4a58bd6dd8dcf584245e43";
        string appkey = "45ac0caedc4786a6b8006a13f82b1c0f";




        public enum MsgTypeEnum
        {
            /// <summary>
            /// 
            /// </summary>
            登陆 = 458771,
            /// <summary>
            /// 
            /// </summary>
            注册 = 458773,
            /// <summary>
            /// 
            /// </summary>
            找回密码 = 458775,
            /// <summary>
            /// 
            /// </summary>
            绑定手机 = 458776,
            /// <summary>
            /// 
            /// </summary>
            付款 = 458777,
            /// <summary>
            /// 
            /// </summary>
            通用 = 458794,
            /// <summary>
            /// 您的注册验证码：{1}，如非本人操作，请忽略本短信！
            /// </summary>
            发送验证码 = 896359,
            /// <summary>
            /// 直推用户{1}购买了{2}商品，请在客户端查看余额变动
            /// </summary>
            购买商品 = 896364,
            /// <summary>
            /// 您的验证码是：{1}，您正在通过手机找回密码，为了保证账户安全，请勿向他人泄露。如非本人操作，请忽略！
            /// </summary>
            找回密码yxyc = 896373,
            /// <summary>
            /// 客户预约下单：您有新订单，联系人：{1}，订单编号：{2}，请您在电脑上登录后台查看预约信息！
            /// </summary>
            预约下单 = 896378,
        }
        /// <summary>
        /// 发送
        /// </summary>
        /// <returns></returns>
        public SmsSingleSenderResult Send()
        {
            SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
            string[] par = this.context.Split(",");
            return ssender.sendWithParam(
                 "86",
                 phone,
                 this.templateId,
                 //new[] { this.context }, 
                 par,
                 this.sign,
                 string.Empty,
                 string.Empty);
        }
        public class SMSParameter
        {
            /// <summary>
            /// 接收方手机号
            /// </summary>
            public string toPhone { get; set; }

            /// <summary>
            /// 签名
            /// </summary>
            public string sign { get; set; } = "Itool";

            /// <summary>
            /// 内容
            /// </summary>
            public string context { get; set; }


            /// <summary>
            /// 短信模板ID
            /// </summary>
            public int templateId { get; set; }
        }
    }
}
